package zemberek3.lexicon;

import zemberek3.structure.IdItem;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class SimpleRegistry<T extends IdItem> {
    Map<String, T> idMap = new HashMap<String, T>();
    Set<T> itemSet = new HashSet<T>();

    public void add(T item) {
        idMap.put(item.id, item);
        itemSet.add(item);
    }

    public void addAll(T... items) {
        for (T item : items) {
            add(item);
        }
    }

    public void addAll(Iterable<T> items) {
        for (T item : items) {
            add(item);
        }
    }

    public void addAll(Iterable<T>... iterables) {
        for (Iterable<T> iterable : iterables) {
            for (T item : iterable) {
                add(item);
            }
        }
    }

    public T get(String id) {
        return idMap.get(id);
    }

}
